package com.mall.business.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.business.domain.TWallet;
import com.mall.common.utils.DateUtils;
import com.mall.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mall.business.mapper.TSocreMapper;
import com.mall.business.domain.TSocre;
import com.mall.business.service.ITSocreService;

/**
 * 积分明细Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Service
public class TSocreServiceImpl extends ServiceImpl<TSocreMapper,TSocre>  implements ITSocreService
{
    @Autowired
    private TSocreMapper tSocreMapper;

    /**
     * 查询积分明细
     *
     * @param id 积分明细主键
     * @return 积分明细
     */
    @Override
    public TSocre selectTSocreById(String id)
    {
        return tSocreMapper.selectTSocreById(id);
    }

    /**
     * 查询积分明细列表
     *
     * @param tSocre 积分明细
     * @return 积分明细
     */
    @Override
    public List<TSocre> selectTSocreList(TSocre tSocre)
    {
        return tSocreMapper.selectTSocreList(tSocre);
    }

    /**
     * 新增积分明细
     *
     * @param tSocre 积分明细
     * @return 结果
     */
    @Override
    public int insertTSocre(TSocre tSocre)
    {
                tSocre.setCreateTime(DateUtils.getNowDate());
            return tSocreMapper.insertTSocre(tSocre);
    }

    /**
     * 修改积分明细
     *
     * @param tSocre 积分明细
     * @return 结果
     */
    @Override
    public int updateTSocre(TSocre tSocre)
    {
                tSocre.setUpdateTime(DateUtils.getNowDate());
        return tSocreMapper.updateTSocre(tSocre);
    }

    /**
     * 批量删除积分明细
     *
     * @param ids 需要删除的积分明细主键
     * @return 结果
     */
    @Override
    public int deleteTSocreByIds(String[] ids)
    {
        return tSocreMapper.deleteTSocreByIds(ids);
    }

    /**
     * 删除积分明细信息
     *
     * @param id 积分明细主键
     * @return 结果
     */
    @Override
    public int deleteTSocreById(String id)
    {
        return tSocreMapper.deleteTSocreById(id);
    }

    // 用户积分余额

    @Override
    public BigDecimal getTotalScore(){
        QueryWrapper<TSocre> tWrapper = new QueryWrapper<TSocre>();
        tWrapper.select("COALESCE(SUM(score), 0) as score");
        TSocre tSocre = this.getOne(tWrapper);
        BigDecimal score = tSocre.getScore();
        return score;
    }
}
